home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / Marlais 0.3.1 / gc4.1-mac / README < prev    next >
Encoding:
Text File  |  1994-07-26  |  40.7 KB  |  816 lines  |  [TEXT/R*ch]

  1. Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  2. Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
  3.  
  4. THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  5. OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  6.  
  7. Permission is hereby granted to use or copy this program
  8. for any purpose,  provided the above notices are retained on all copies.
  9. Permission to modify the code and to distribute modified code is granted,
  10. provided the above notices are retained, and a notice that the code was
  11. modified is included with the above copyright notice.
  12.  
  13. This is version 4.1 of a conservative garbage collector for C and C++.
  14.  
  15. HISTORY -
  16.  
  17.   Early versions of this collector were developed as a part of research
  18. projects supported in part by the National Science Foundation
  19. and the Defense Advance Research Projects Agency.
  20. Much of the code was rewritten by Hans-J. Boehm at Xerox PARC.
  21. The SPARC specific code was contributed by Mark Weiser
  22. (weiser@parc.xerox.com).  The Encore Multimax modifications were supplied by
  23. Kevin Kenny (kenny@m.cs.uiuc.edu).  The adaptation to the RT is largely due
  24. to Vernon Lee (scorpion@rice.edu), on machines made available by IBM.
  25. Much of the HP specific code and a number of good suggestions for improving the
  26. generic code are due to Walter Underwood (wunder@hp-ses.sde.hp.com).
  27. Robert Brazile (brazile@diamond.bbn.com) originally supplied the ULTRIX code.
  28. Al Dosser (dosser@src.dec.com) and Regis Cridlig (Regis.Cridlig@cl.cam.ac.uk)
  29. subsequently provided updates and information on variation between ULTRIX
  30. systems.  Parag Patel (parag@netcom.com) supplied the A/UX code.
  31. Jesper Peterson(jep@mtiame.mtia.oz.au) supplied the Amiga port.
  32. Thomas Funke (thf@zelator.in-berlin.de(?)) supplied the NeXT port.
  33. Bill Janssen (janssen@parc.xerox.com) supplied the SunOS dynamic loader
  34. specific code. Manuel Serrano (serrano@cornas.inria.fr) supplied linux and
  35. Sony News specific code.  Al Dosser provided Alpha/OSF/1 code.  He and
  36. Dave Detlefs(detlefs@src.dec.com) also provided several generic bug fixes.
  37. Alistair G. Crooks(agc@uts.amdahl.com) supplied the NetBSD and 386BSD ports.
  38. Jeffrey Hsu (hsu@soda.berkeley.edu) provided the FreeBSD port.
  39. Brent Benson (brent@jade.ssd.csd.harris.com) ported the collector to
  40. a Motorola 88K processor running CX/UX (Harris NightHawk).
  41. Ari Huttunen (Ari.Huttunen@hut.fi) generalized the OS/2 port to
  42. nonIBM development environments (a nontrivial task).
  43. David Chase, then at Olivetti Research, suggested several improvements.
  44. Scott Schwartz (schwartz@groucho.cse.psu.edu) supplied some of the
  45. code to save and print call stacks for leak detection on a SPARC.
  46. Jesse Hull and John Ellis supplied the C++ interface code.
  47. Zhong Shao performed much of the experimentation that led to the
  48. current typed allocation facility.  (His dynamic type inference code hasn't
  49. made it into the released version of the collector, yet.)
  50. (Blame for misinstallation of these modifications goes to the first author,
  51. however.)
  52.  
  53.     This is intended to be a general purpose, garbage collecting storage
  54. allocator.  The algorithms used are described in:
  55.  
  56. Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative Environment",
  57. Software Practice & Experience, September 1988, pp. 807-820.
  58.  
  59. Boehm, H., A. Demers, and S. Shenker, "Mostly Parallel Garbage Collection",
  60. Proceedings of the ACM SIGPLAN '91 Conference on Programming Language Design
  61. and Implementation, SIGPLAN Notices 26, 6 (June 1991), pp. 157-164.
  62.  
  63. Boehm, H., "Space Efficient Conservative Garbage Collection", Proceedings
  64. of the ACM SIGPLAN '91 Conference on Programming Language Design and
  65. Implementation, SIGPLAN Notices 28, 6 (June 1993), pp. 197-206.
  66.  
  67.   Unlike the collector described in the second reference, this collector
  68. operates either with the mutator stopped during the entire collection
  69. (default) or incrementally during allocations.  (The latter is supported
  70. on only a few machines.)  It does not rely on threads, but is intended
  71. to be thread-safe.
  72.  
  73.   Some of the ideas underlying the collector have previously been explored
  74. by others.  (Doug McIlroy wrote a vaguely similar collector that is part of
  75. version 8 UNIX (tm).)  However none of this work appears to have been widely
  76. disseminated.
  77.  
  78.   Rudimentary tools for use of the collector as a leak detector are included, as
  79. is a fairly sophisticated string package "cord" that makes use of the collector.
  80. (See cord/README.)
  81.  
  82.  
  83. GENERAL DESCRIPTION
  84.  
  85.   This is a garbage colecting storage allocator that is intended to be
  86. used as a plug-in replacement for C's malloc.
  87.  
  88.   Since the collector does not require pointers to be tagged, it does not
  89. attempt to ensure that all inaccessible storage is reclaimed.  However,
  90. in our experience, it is typically more successful at reclaiming unused
  91. memory than most C programs using explicit deallocation.  Unlike manually
  92. introduced leaks, the amount of unreclaimed memory typically stays
  93. bounded.
  94.  
  95.   In the following, an "object" is defined to be a region of memory allocated
  96. by the routines described below.  
  97.  
  98.   Any objects not intended to be collected must be pointed to either
  99. from other such accessible objects, or from the registers,
  100. stack, data, or statically allocated bss segments.  Pointers from
  101. the stack or registers may point to anywhere inside an object.
  102. However, it is usually assumed that all pointers originating in the
  103. heap point to the beginning of an object.  (This does
  104. not disallow interior pointers; it simply requires that there must be a
  105. pointer to the beginning of every accessible object, in addition to any
  106. interior pointers.)  There are two facilities for altering this behavior.
  107. The macro ALL_INTERIOR_POINTERS may be defined in gc_private.h to
  108. cause any pointer into an object (or one past the end) to retain the
  109. object.  A routine GC_register_displacement is provided to allow for
  110. more controlled interior pointer use in the heap.  Defining
  111. ALL_INTERIOR_POINTERS is somewhat dangerous, in that it can result
  112. in unnecessary memroy retention.  However this is much less of a
  113. problem than with older collector versions.  The routine
  114. GC_register_displacement is described in gc.h.
  115.  
  116.   Note that pointers inside memory allocated by the standard "malloc" are not
  117. seen by the garbage collector.  Thus objects pointed to only from such a
  118. region may be prematurely deallocated.  It is thus suggested that the
  119. standard "malloc" be used only for memory regions, such as I/O buffers, that
  120. are guaranteed not to contain pointers.  Pointers in C language automatic,
  121. static, or register variables, are correctly recognized.  (Note that
  122. GC_malloc_uncollectable has semantics similar to standard malloc,
  123. but allocates objects that are traced by the collector.)
  124.  
  125.   The collector does not generally know how to find pointers in data
  126. areas that are associated with dynamic libraries.  This is easy to
  127. remedy IF you know how to find those data areas on your operating
  128. system (see GC_add_roots).  Code for doing this under SunOS and IRIX 5.X is
  129. included (see dynamic_load.c).
  130.  
  131.   Note that the garbage collector does not need to be informed of shared
  132. read-only data.  However if the shared library mechanism can introduce
  133. discontiguous data areas that may contain pointers, then the collector does
  134. need to be informed.
  135.  
  136.   Signal processing for most signals is normally deferred during collection,
  137. and during uninterruptible parts of the allocation process.  Unlike
  138. standard ANSI C mallocs, it is intended to be safe to invoke malloc
  139. from a signal handler while another malloc is in progress, provided
  140. the original malloc is not restarted.  (Empirically, many UNIX
  141. applications already asssume this.)  Even this modest level of signal-
  142. safety may be too expensive on some systems.  If so, ENABLE_SIGNALS
  143. and DISABLE_SIGNALS may be redefined to the empty statement in gc_private.h.
  144.  
  145.   The allocator/collector can also be configured for thread-safe operation.
  146. (Full signal safety can also be acheived, but only at the cost of two system
  147. calls per malloc, which is usually unacceptable.)
  148.  
  149. INSTALLATION AND PORTABILITY
  150.  
  151.   As distributed, the macro SILENT is defined in Makefile.
  152. In the event of problems, this can be removed to obtain a moderate
  153. amount of descriptive output for each collection.
  154. (The given statistics exhibit a few peculiarities.
  155. Things don't appear to add up for a variety of reasons, most notably
  156. fragmentation losses.  These are probably much more significant for the
  157. contrived program "test.c" than for your application.)
  158.  
  159.   Note that typing "make test" will automatically build the collector
  160. and then run setjmp_test and gctest. Setjmp_test will give you information
  161. about configuring the collector, which is useful primarily if you have
  162. a machine that's not already supported.  Gctest is a somewhat superficial
  163. test of collector functionality.  Failure is indicated by a core dump or
  164. a message to the effect that the collector is broken.  Gctest takes about 
  165. 35 seconds to run on a SPARCstation 2. On a slower machine,
  166. expect it to take a while.  It may use up to 8 MB of memory.  (The
  167. multi-threaded version will use more.)  "Make test" will also, as
  168. its last step, attempt to build and test the "cord" string library.
  169. This will fail without an ANSI C compiler.
  170.  
  171.   The Makefile will generate a library gc.a which you should link against.
  172. Typing "make cords" will add the cord library to gc.a.
  173. Note that this requires an ANSI C compiler.
  174.  
  175.   It is suggested that if you need to replace a piece of the collector
  176. (e.g. GC_mark_rts.c) you simply list your version ahead of gc.a on the
  177. ld command line, rather than replacing the one in gc.a.  (This will
  178. generate numerous warnings under some versions of AIX, but it still
  179. works.)
  180.  
  181.   All include files that need to be used by clients will be put in the
  182. include subdirectory.  (Normally this is just gc.h.  "Make cords" adds
  183. "cord.h" and "ec.h".)
  184.  
  185.   The collector currently is designed to run essentially unmodified on
  186. the following machines (most of the operating systems mentioned are
  187. trademarks of their respective holders):
  188.  
  189.         Sun 3
  190.         Sun 4 under SunOS 4.X or Solaris2.X (with or without threads)
  191.         Vax under 4.3BSD, Ultrix
  192.         Intel 386 or 486 under many operating systems, but not MSDOS.
  193.             (Win32S is somewhat supported, so it is possible to
  194.             build applications for Windows 3.1)
  195.         Sequent Symmetry  (single threaded)
  196.         Encore Multimax   (single threaded)
  197.         MIPS M/120 (and presumably M/2000) (RISC/os 4.0 with BSD libraries)
  198.         IBM PC/RT  (Berkeley UNIX)
  199.         IBM RS/6000
  200.         HP9000/300
  201.         HP9000/700
  202.         DECstations under Ultrix
  203.         DEC Alpha running OSF/1
  204.         SGI workstations under IRIX
  205.         Sony News
  206.         Apple MacIntosh under A/UX
  207.         Commodore Amiga (see README.amiga)
  208.         NeXT machines
  209.  
  210.   In a few cases (Amiga, OS/2, Win32) a separate makefile is supplied.
  211.  
  212.   Dynamic libraries are completely supported only under SunOS
  213. (and even that support is not functional on the last Sun 3 release),
  214. IRIX 5, Win32 (not Win32S) and OSF/1 on DEC AXP machines.
  215. On other machines we recommend that you do one of the following:
  216.  
  217.   1) Add dynamic library support (and send us the code).
  218.   2) Use static versions of the libraries.
  219.   3) Arrange for dynamic libraries to use the standard malloc.
  220.      This is still dangerous if the library stores a pointer to a
  221.      garbage collected object.  But nearly all standard interfaces
  222.      prohibit this, because they deal correctly with pointers
  223.      to stack allocated objects.  (Strtok is an exception.  Don't
  224.      use it.)
  225.  
  226.   In all cases we assume that pointer alignment is consistent with that
  227. enforced by the standard C compilers.  If you use a nonstandard compiler
  228. you may have to adjust the alignment parameters defined in gc_private.h.
  229.  
  230.   A port to a machine that is not byte addressed, or does not use 32 bit
  231. addresses will require a major effort.  (Parts of the code try to anticipate
  232. 64 bit addresses.  Others will need to be rewritten, since different data
  233. structures are needed.)  A port to MSDOS is hopeless, unless you are willing
  234. to assume an 80386 or better, and that only flat 32 bit pointers will ever be
  235. used.
  236.  
  237.   For machines not already mentioned, or for nonstandard compilers, the
  238. following are likely to require change:
  239.  
  240. 1.  The parameters at the top of gc_private.h.
  241.       The parameters that will usually require adjustment are
  242.    STACKBOTTOM,  ALIGNMENT and DATASTART.  Setjmp_test
  243.    prints its guesses of the first two.
  244.       DATASTART should be an expression for computing the
  245.    address of the beginning of the data segment.  This can often be
  246.    &etext.  But some memory management units require that there be
  247.    some unmapped space between the text and the data segment.  Thus
  248.    it may be more complicated.   On UNIX systems, this is rarely
  249.    documented.  But the adb "$m" command may be helpful.  (Note
  250.    that DATASTART will usually be a function of &etext.  Thus a
  251.    single experiment is usually insufficient.)
  252.      STACKBOTTOM is used to initialize GC_stackbottom, which
  253.    should be a sufficient approximation to the coldest stack address.
  254.    On some machines, it is difficult to obtain such a value that is
  255.    valid across a variety of MMUs, OS releases, etc.  A number of
  256.    alternatives exist for using the collector in spite of this.  See the
  257.    discussion in config.h.h immediately preceding the various
  258.    definitions of STACKBOTTOM.
  259.    
  260. 2.  mach_dep.c.
  261.       The most important routine here is one to mark from registers.
  262.     The distributed file includes a generic hack (based on setjmp) that
  263.     happens to work on many machines, and may work on yours.  Try
  264.     compiling and running setjmp_test.c to see whether it has a chance of
  265.     working.  (This is not correct C, so don't blame your compiler if it
  266.     doesn't work.  Based on limited experience, register window machines
  267.     are likely to cause trouble.  If your version of setjmp claims that
  268.     all accessible variables, including registers, have the value they
  269.     had at the time of the longjmp, it also will not work.  Vanilla 4.2 BSD
  270.     makes such a claim.  SunOS does not.)
  271.       If your compiler does not allow in-line assembly code, or if you prefer
  272.     not to use such a facility, mach_dep.c may be replaced by a .s file
  273.     (as we did for the MIPS machine and the PC/RT).
  274.  
  275. 3.  mark_roots.c.
  276.       These are the top level mark routines that determine which sections
  277.     of memory the collector should mark from.  This is normally not
  278.     architecture specific (aside from the macros defined in gc_private.h and
  279.     referenced here), but it can be programming language and compiler
  280.     specific.  The supplied routine should work for most C compilers
  281.     running under UNIX.  Calls to GC_add_roots may sometimes be used
  282.     for similar effect.
  283.  
  284. 4.  The sigsetmask call does not appear to exist under early system V UNIX.
  285.     It is used by the collector to block and unblock signals at times at
  286.     which an asynchronous allocation inside a signal handler could not
  287.     be tolerated.  Under system V, it is possible to remove these calls,
  288.     provided no storage allocation is done by signal handlers.  The
  289.     alternative is to issue a sequence of system V system calls, one per
  290.     signal that is actually used.  This may be a bit slow.
  291.  
  292.   For a different versions of Berkeley UN*X or different machines using the
  293. Motorola 68000, Vax, SPARC, 80386, NS 32000, PC/RT, or MIPS architecture,
  294. it should frequently suffice to change definitions in gc_private.h.
  295.  
  296.  
  297. THE C INTERFACE TO THE ALLOCATOR
  298.  
  299.   The following routines are intended to be directly called by the user.
  300. Note that usually only GC_malloc is necessary.  GC_clear_roots and GC_add_roots
  301. calls may be required if the collector has to trace from nonstandard places
  302. (e.g. from dynamic library data areas on a machine on which the 
  303. collector doesn't already understand them.)  On some machines, it may
  304. be desirable to set GC_stacktop to a good approximation of the stack base. 
  305. (This enhances code portability on HP PA machines, since there is no
  306. good way for the collector to compute this value.)  Client code may include
  307. "gc.h", which defines all of the following, plus a few others.
  308.  
  309. 1)  GC_malloc(nbytes)
  310.     - allocate an object of size nbytes.  Unlike malloc, the object is
  311.       cleared before being returned to the user.  Gc_malloc will
  312.       invoke the garbage collector when it determines this to be appropriate.
  313.       GC_malloc may return 0 if it is unable to acquire sufficient
  314.       space from the operating system.  This is the most probable
  315.       consequence of running out of space.  Other possible consequences
  316.       are that a function call will fail due to lack of stack space,
  317.       or that the collector will fail in other ways because it cannot
  318.       maintain its internal data structures, or that a crucial system
  319.       process will fail and take down the machine.  Most of these
  320.       possibilities are independent of the malloc implementation.
  321.  
  322. 2)  GC_malloc_atomic(nbytes)
  323.     - allocate an object of size nbytes that is guaranteed not to contain any
  324.       pointers.  The returned object is not guaranteed to be cleeared.
  325.       (Can always be replaced by GC_malloc, but results in faster collection
  326.       times.  The collector will probably run faster if large character
  327.       arrays, etc. are allocated with GC_malloc_atomic than if they are
  328.       statically allocated.)
  329.  
  330. 3)  GC_realloc(object, new_size)
  331.     - change the size of object to be new_size.  Returns a pointer to the
  332.       new object, which may, or may not, be the same as the pointer to
  333.       the old object.  The new object is taken to be atomic iff the old one
  334.       was.  If the new object is composite and larger than the original object,
  335.       then the newly added bytes are cleared (we hope).  This is very likely
  336.       to allocate a new object, unless MERGE_SIZES is defined in gc_private.h.
  337.       Even then, it is likely to recycle the old object only if the object
  338.       is grown in small additive increments (which, we claim, is generally bad
  339.       coding practice.)
  340.  
  341. 4)  GC_free(object)
  342.     - explicitly deallocate an object returned by GC_malloc or
  343.       GC_malloc_atomic.  Not necessary, but can be used to minimize
  344.       collections if performance is critical.
  345.  
  346. 5)  GC_expand_hp(number_of_4K_blocks)
  347.     - Explicitly increase the heap size.  (This is normally done automatically
  348.       if a garbage collection failed to GC_reclaim enough memory.  Explicit
  349.       calls to GC_expand_hp may prevent unnecessarily frequent collections at
  350.       program startup.)
  351.       
  352. 6)  GC_clear_roots()
  353.     - Reset the collectors idea of where static variables containing pointers
  354.       may be located to the empty set of locations.  No statically allocated
  355.       variables will be traced from after this call, unless there are
  356.       intervening GC_add_roots calls.  The collector will still trace from
  357.       registers and the program stack.
  358.       
  359. 7)  GC_add_roots(low_address, high_address_plus_1)
  360.     - Add [low_address, high_address) as an area that may contain root pointers
  361.       and should be traced by the collector.  The static data and bss segments
  362.       are considered by default, and should not be added unless GC_clear_roots
  363.       has been called.  The number of root areas is currently limited to 50.
  364.       This is intended as a way to register data areas for dynamic libraries,
  365.       or to replace the entire data ans bss segments by smaller areas that are
  366.       known to contain all the roots. 
  367.  
  368. 8) Several routines to allow for registration of finalization code.
  369.    User supplied finalization code may be invoked when an object becomes
  370.    unreachable.  To call (*f)(obj, x) when obj becomes inaccessible, use
  371.     GC_register_finalizer(obj, f, x, 0, 0);
  372.    For more sophisticated uses, and for finalization ordering issues,
  373.    see gc.h.
  374.  
  375.   The global variable GC_free_space_divisor may be adjusted up from its
  376. default value of 4 to use less space and more collection time, or down for
  377. the opposite effect.  Setting it to 1 or 0 will effectively disable collections
  378. and cause all allocations to simply grow the heap.
  379.  
  380.   The variable GC_non_gc_bytes, which is normally 0, may be changed to reflect
  381. the amount of memory allocated by the above routines that should not be
  382. considered as a candidate for collection.  Careless use may, of course, result
  383. in excessive memory consumption.
  384.  
  385.   Some additional tuning is possible through the parameters defined
  386. near the top of gc_private.h.
  387.   
  388.   If only GC_malloc is intended to be used, it might be appropriate to define:
  389.  
  390. #define malloc(n) GC_malloc(n)
  391. #define calloc(m,n) GC_malloc((m)*(n))
  392.  
  393.   For small pieces of VERY allocation intensive code, gc_inl.h
  394. includes some allocation macros that may be used in place of GC_malloc
  395. and friends.
  396.  
  397.   All externally visible names in the garbage collector start with "GC_".
  398. To avoid name conflicts, client code should avoid this prefix, except when
  399. accessing garbage collector routines or variables.
  400.  
  401.   Thre are provisions for allocation with explicit type information.
  402. This is rarely necessary.  Details can be found in gc_typed.h.
  403.  
  404.  
  405. USE AS LEAK DETECTOR:
  406.  
  407.   The collector may be used to track down leaks in C programs that are
  408. intended to run with malloc/free (e.g. code with extreme real-time or
  409. portability constraints).  To do so define FIND_LEAK somewhere in
  410. gc_priv.h.  This will cause the collector to invoke the report_leak
  411. routine defined near the top of reclaim.c whenever an inaccessible
  412. object is found that has not been explicitly freed.
  413.   Productive use of this facility normally involves redefining report_leak
  414. to do something more intelligent.  This typically requires annotating
  415. objects with additional information (e.g. creation time stack trace) that
  416. identifies their origin.  Such code is typically not very portable, and is
  417. not included here, except on SPARC machines.
  418.   If all objects are allocated with GC_DEBUG_MALLOC (see next section),
  419. then the default version of report_leak will report the source file
  420. and line number at which the leaked object was allocated.  This may
  421. sometimes be sufficient.  (On SPARC/SUNOS4 machines, it will also report
  422. a cryptic stack trace.  This can often be turned into a sympolic stack
  423. trace by invoking program "foo" with "callprocs foo".  Callprocs is
  424. a short shell script that invokes adb to expand program counter values
  425. to symbolic addresses.  It was largely supplied by Scott Schwartz.)
  426.   Note that the debugging facilities described in the next section can
  427. sometimes be slightly LESS effective in leak finding mode, since in
  428. leak finding mode, GC_debug_free actually results in reuse of the object.
  429. (Otherwise the object is simply marked invalid.)
  430.  
  431. DEBUGGING FACILITIES:
  432.  
  433.   The routines GC_debug_malloc, GC_debug_malloc_atomic, GC_debug_realloc,
  434. and GC_debug_free provide an alternate interface to the collector, which
  435. provides some help with memory overwrite errors, and the like.
  436. Objects allocated in this way are annotated with additional
  437. information.  Some of this information is checked during garbage
  438. collections, and detected inconsistencies are reported to stderr.
  439.  
  440.   Simple cases of writing past the end of an allocated object should
  441. be caught if the object is explicitly deallocated, or if the
  442. collector is invoked while the object is live.  The first deallocation
  443. of an object will clear the debugging info associated with an
  444. object, so accidentally repeated calls to GC_debug_free will report the
  445. deallocation of an object without debugging information.  Out of
  446. memory errors will be reported to stderr, in addition to returning
  447. NIL.
  448.  
  449.   GC_debug_malloc checking  during garbage collection is enabled
  450. with the first call to GC_debug_malloc.  This will result in some
  451. slowdown during collections.  If frequent heap checks are desired,
  452. this can be acheived by explicitly invoking GC_gcollect, e.g. from
  453. the debugger.
  454.  
  455.   GC_debug_malloc allocated objects should not be passed to GC_realloc
  456. or GC_free, and conversely.  It is however acceptable to allocate only
  457. some objects with GC_debug_malloc, and to use GC_malloc for other objects,
  458. provided the two pools are kept distinct.  In this case, there is a very
  459. low probablility that GC_malloc allocated objects may be misidentified as
  460. having been overwritten.  This should happen with probability at most
  461. one in 2**32.  This probability is zero if GC_debug_malloc is never called.
  462.  
  463.   GC_debug_malloc, GC_malloc_atomic, and GC_debug_realloc take two
  464. additional trailing arguments, a string and an integer.  These are not
  465. interpreted by the allocator.  They are stored in the object (the string is
  466. not copied).  If an error involving the object is detected, they are printed.
  467.  
  468.   The macros GC_MALLOC, GC_MALLOC_ATOMIC, GC_REALLOC, GC_FREE, and
  469. GC_REGISTER_FINALIZER are also provided.  These require the same arguments
  470. as the corresponding (nondebugging) routines.  If gc.h is included
  471. with GC_DEBUG defined, they call the debugging versions of these
  472. functions, passing the current file name and line number as the two
  473. extra arguments, where appropriate.  If gc.h is included without GC_DEBUG
  474. defined, then all these macros will instead be defined to their nondebugging
  475. equivalents.  (GC_REGISTER_FINALIZER is necessary, since pointers to
  476. objects with debugging information are really pointers to a displacement
  477. of 16 bytes form the object beginning, and some translation is necessary
  478. when finalization routines are invoked.  For details, about what's stored
  479. in the header, see the definition of the type oh in debug_malloc.c)
  480.  
  481. INCREMENTAL/GENERATIONAL COLLECTION:
  482.  
  483. The collector normally interrupts client code for the duration of 
  484. a garbage collection mark phase.  This may be unacceptable if interactive
  485. response is needed for programs with large heaps.  The collector
  486. can also run in a "generational" mode, in which it usually attempts to
  487. collect only objects allocated since the last garbage collection.
  488. Furthermore, in this mode, garbage collections run mostly incrementally,
  489. with a small amount of work performed in response to each of a large number of
  490. GC_malloc requests.
  491.  
  492. This mode is enabled by a call to GC_enable_incremental().
  493.  
  494. Incremental and generational collection is effective in reducing
  495. pause times only if the collector has some way to tell which objects
  496. or pages have been recently modified.  The collector uses two sources
  497. of information:
  498.  
  499. 1. Information provided by the VM system.  This may be provided in
  500. one of several forms.  Under Solaris 2.X (and potentially under other
  501. similar systems) information on dirty pages can be read from the
  502. /proc file system.  Under other systems (currently SunOS4.X) it is
  503. possible to write-protect the heap, and catch the resulting faults.
  504. On these systems we require that system calls writing to the heap
  505. (other than read) be handled specially by client code.
  506. See os_dep.c for details.
  507.  
  508. 2. Information supplied by the programmer.  We define "stubborn"
  509. objects to be objects that are rarely changed.  Such an object
  510. can be allocated (and enabled for writing) with GC_malloc_stubborn.
  511. Once it has been initialized, the collector should be informed with
  512. a call to GC_end_stubborn_change.  Subsequent writes that store
  513. pointers into the object must be preceded by a call to
  514. GC_change_stubborn.
  515.  
  516. This mechanism performs best for objects that are written only for
  517. initialization, and such that only one stubborn object is writable
  518. at once.  It is typically not worth using for short-lived
  519. objects.  Stubborn objects are treated less efficiently than pointerfree
  520. (atomic) objects.
  521.  
  522. A rough rule of thumb is that, in the absence of VM information, garbage
  523. collection pauses are proportional to the amount of pointerful storage
  524. plus the amount of modified "stubborn" storage that is reachable during
  525. the collection.  
  526.  
  527. Initial allocation of stubborn objects takes longer than allocation
  528. of other objects, since other data structures need to be maintained.
  529.  
  530. We recommend against random use of stubborn objects in client
  531. code, since bugs caused by inappropriate writes to stubborn objects
  532. are likely to be very infrequently observed and hard to trace.  
  533. However, their use may be appropriate in a few carefully written
  534. library routines that do not make the objects themselves available
  535. for writing by client code.
  536.  
  537.  
  538. BUGS:
  539.  
  540.   Any memory that does not have a recognizable pointer to it will be
  541. reclaimed.  Exclusive-or'ing forward and backward links in a list
  542. doesn't cut it.
  543.   Some C optimizers may lose the last undisguised pointer to a memory
  544. object as a consequence of clever optimizations.  This has almost
  545. never been observed in practice.  Send mail to boehm@parc.xerox.com
  546. for suggestions on how to fix your compiler.
  547.   This is not a real-time collector.  In the standard configuration,
  548. percentage of time required for collection should be constant across
  549. heap sizes.  But collection pauses will increase for larger heaps.
  550. (On SPARCstation 2s collection times will be on the order of 300 msecs
  551. per MB of accessible memory that needs to be scanned.  Your mileage
  552. may vary.)  The incremental/generational collection facility helps,
  553. but is portable only if "stubborn" allocation is used.
  554.   Please address bug reports to boehm@parc.xerox.com.  If you are
  555. contemplating a major addition, you might also send mail to ask whether
  556. it's already been done.
  557.  
  558. RECENT VERSIONS:
  559.  
  560.   Version 1.3 and immediately preceding versions contained spurious
  561. assembly language assignments to TMP_SP.  Only the assignment in the PC/RT
  562. code is necessary.  On other machines, with certain compiler options,
  563. the assignments can lead to an unsaved register being overwritten.
  564. Known to cause problems under SunOS 3.5 WITHOUT the -O option.  (With
  565. -O the compiler recognizes it as dead code.  It probably shouldn't,
  566. but that's another story.)
  567.  
  568.   Version 1.4 and earlier versions used compile time determined values
  569. for the stack base.  This no longer works on Sun 3s, since Sun 3/80s use
  570. a different stack base.  We now use a straightforward heuristic on all
  571. machines on which it is known to work (incl. Sun 3s) and compile-time
  572. determined values for the rest.  There should really be library calls
  573. to determine such values.
  574.  
  575.   Version 1.5 and earlier did not ensure 8 byte alignment for objects
  576. allocated on a sparc based machine.
  577.  
  578.   Version 1.8 added ULTRIX support in gc_private.h.
  579.   
  580.   Version 1.9 fixed a major bug in gc_realloc.
  581.   
  582.   Version 2.0 introduced a consistent naming convention for collector
  583. routines and added support for registering dynamic library data segments
  584. in the standard mark_roots.c.  Most of the data structures were revamped.
  585. The treatment of interior pointers was completely changed.  Finalization
  586. was added.  Support for locking was added.  Object kinds were added.
  587. We added a black listing facility to avoid allocating at addresses known
  588. to occur as integers somewhere in the address space.  Much of this
  589. was accomplished by adapting ideas and code from the PCR collector.
  590. The test program was changed and expanded.
  591.  
  592.   Version 2.1 was the first stable version since 1.9, and added support
  593. for PPCR.
  594.  
  595.   Version 2.2 added debugging allocation, and fixed various bugs.  Among them:
  596. - GC_realloc could fail to extend the size of the object for certain large object sizes.
  597. - A blatant subscript range error in GC_printf, which unfortunately
  598.   wasn't excercised on machines with sufficient stack alignment constraints.
  599. - GC_register_displacement did the wrong thing if it was called after
  600.   any allocation had taken place.
  601. - The leak finding code would eventually break after 2048 byte
  602.   byte objects leaked.
  603. - interface.c didn't compile.
  604. - The heap size remained much too small for large stacks.
  605. - The stack clearing code behaved badly for large stacks, and perhaps
  606.   on HP/PA machines.
  607.  
  608.   Version 2.3 added ALL_INTERIOR_POINTERS and fixed the following bugs:
  609. - Missing declaration of etext in the A/UX version.
  610. - Some PCR root-finding problems.
  611. - Blacklisting was not 100% effective, because the plausible future
  612.   heap bounds were being miscalculated.
  613. - GC_realloc didn't handle out-of-memory correctly.
  614. - GC_base could return a nonzero value for addresses inside free blocks.
  615. - test.c wasn't really thread safe, and could erroneously report failure
  616.   in a multithreaded environment.  (The locking primitives need to be
  617.   replaced for other threads packages.)
  618. - GC_CONS was thoroughly broken.
  619. - On a SPARC with dynamic linking, signals stayed diabled while the
  620.   client code was running.
  621.   (Thanks to Manuel Serrano at INRIA for reporting the last two.)
  622.   
  623.   Version 2.4 added GC_free_space_divisor as a tuning knob, added
  624.   support for OS/2 and linux, and fixed the following bugs:
  625. - On machines with unaligned pointers (e.g. Sun 3), every 128th word could
  626.   fail to be considered for marking.
  627. - Dynamic_load.c erroneously added 4 bytes to the length of the data and
  628.   bss sections of the dynamic library.  This could result in a bad memory
  629.   reference if the actual length was a multiple of a page.  (Observed on
  630.   Sun 3.  Can probably also happen on a Sun 4.)
  631.   (Thanks to Robert Brazile for pointing out that the Sun 3 version
  632.   was broken.  Dynamic library handling is still broken on Sun 3s
  633.   under 4.1.1U1, but apparently not 4.1.1.  If you have such a machine,
  634.   use -Bstatic.)
  635.   
  636.   Version 2.5 fixed the following bugs:
  637. - Removed an explicit call to exit(1)
  638. - Fixed calls to GC_printf and GC_err_printf, so the correct number of
  639.   arguments are always supplied.  The OS/2 C compiler gets confused if
  640.   the number of actuals and the number of formals differ.  (ANSI C
  641.   doesn't require this to work.  The ANSI sanctioned way of doing things
  642.   causes too many compatibility problems.)
  643.   
  644.   Version 3.0  added generational/incremental collection and stubborn
  645.   objects.
  646.  
  647.   Version 3.1 added the following features:
  648. - A workaround for a SunOS 4.X SPARC C compiler
  649.   misfeature that caused problems when the collector was turned into
  650.   a dynamic library.  
  651. - A fix for a bug in GC_base that could result in a memory fault.
  652. - A fix for a performance bug (and several other misfeatures) pointed
  653.   out by Dave Detelfs and Al Dosser.
  654. - Use of dirty bit information for static data under Solaris 2.X.
  655. - DEC Alpha/OSF1 support (thanks to Al Dosser).
  656. - Incremental collection on more platforms.
  657. - A more refined heap expansion policy.  Less space usage by default.
  658. - Various minor enhancements to reduce space usage, and to reduce
  659.   the amount of memory scanned by the collector.
  660. - Uncollectable allocation without per object overhead.
  661. - More conscientious handling of out-of-memory conditions.
  662. - Fixed a bug in debugging stubborn allocation.
  663. - Fixed a bug that resulted in occasional erroneous reporting of smashed
  664.   objects with debugging allocation.
  665. - Fixed bogus leak reports of size 4096 blocks with FIND_LEAK.
  666.  
  667.   Version 3.2 fixed a serious and not entirely repeatable bug in
  668.   the incremental collector.  It appeared only when dirty bit info
  669.   on the roots was available, which is normally only under Solaris.
  670.   It also added GC_general_register_disappearing_link, and some
  671.   testing code.  Interface.c disappeared.
  672.  
  673.   Version 3.3 fixes several bugs and adds new ports:
  674. - PCR-specific bugs.
  675. - Missing locking in GC_free, redundant FASTUNLOCK
  676.   in GC_malloc_stubborn, and 2 bugs in
  677.   GC_unregister_disappearing_link.
  678.   All of the above were pointed out by Neil Sharman
  679.   (neil@cs.mu.oz.au).
  680. - Common symbols allocated by the SunOS4.X dynamic loader
  681.   were not included in the root set.
  682. - Bug in GC_finalize (reported by Brian Beuning and Al Dosser)
  683. - Merged Amiga port from Jesper Peterson (untested)
  684. - Merged NeXT port from Thomas Funke (significantly
  685.   modified and untested)
  686.  
  687.   Version 3.4:
  688. - Fixed a performance bug in GC_realloc.
  689. - Updated the amiga port.
  690. - Added NetBSD and 386BSD ports.
  691. - Added cord library.
  692. - Added trivial performance enhancement for
  693.   ALL_INTERIOR_POINTERS.  (Don't scan last word.)
  694.   
  695.   Version 3.5
  696. - Minor collections now mark from roots only once, if that
  697.   doesn't cause an excessive pause.
  698. - The stack clearing heuristic was refined to prevent anomalies
  699.   with very heavily recursive programs and sparse stacks.
  700. - Fixed a bug that prevented mark stack growth in some cases.
  701.   GC_objects_are_marked should be set to TRUE after a call
  702.   to GC_push_roots and as part of GC_push_marked, since
  703.   both can now set mark bits.  I think this is only a performance
  704.   bug, but I wouldn't bet on it.  It's certainly very hard to argue
  705.   that the old version was correct.
  706. - Fixed an incremental collection bug that prevented it from
  707.   working at all when HBLKSIZE != getpagesize()
  708. - Changed dynamic_loading.c to include gc_private.h before testing
  709.   DYNAMIC_LOADING.  SunOS dynamic library scanning
  710.   must have been broken in 3.4.
  711. - Object size rounding now adapts to program behavior.
  712. - Added a workaround (provided by Manuel Serrano and
  713.   colleagues) to a long-standing SunOS 4.X (and 3.X?) ld bug
  714.   that I had incorrectly assumed to have been squished.
  715.   The collector was broken if the text segment size was within
  716.   32 bytes of a multiple of 8K bytes, and if the beginning of
  717.   the data segment contained interesting roots.  The workaround
  718.   assumes a demand-loadable executable.  The original may have
  719.   have "worked" in some other cases.
  720. - Added dynamic library support under IRIX5.
  721. - Added support for EMX under OS/2 (thanks to Ari Huttunen).
  722.   
  723. Version 3.6:
  724. - fixed a bug in the mark stack growth code that was introduced
  725.   in 3.4.
  726. - fixed Makefile to work around DEC AXP compiler tail recursion
  727.   bug.
  728.  
  729. Version 3.7:
  730. - Added a workaround for an HP/UX compiler bug.
  731. - Fixed another stack clearing performance bug.  Reworked
  732.   that code once more.
  733.   
  734. Version 4.0:
  735. - Added support for Solaris threads (which was possible
  736.   only be reimplementing some fraction of Solaris threads,
  737.   since Sun doesn't currently make the thread debugging
  738.   interface available).
  739. - Added non-threads win32 and win32S support.
  740. - (Grudgingly, with suitable muttering of obscenities) renamed
  741.   files so that the collector distribution could live on a FAT
  742.   file system.  Files that are guaranteed to be useless on
  743.   a PC still have long names.  Gc_inline.h and gc_private.h
  744.   still exist, but now just include  gc_inl.h and gc_priv.h.
  745. - Fixed a really obscure bug in finalization that could cause
  746.   undetected mark stack overflows.  (I would be surprised if
  747.   any real code ever tickled this one.)
  748. - Changed finalization code to dynamically resize the hash
  749.   tables it maintains.  (This probably does not matter for well-
  750.   -written code.  It no doubt does for C++ code that overuses
  751.   destructors.)
  752. - Added typed allocation primitves.  Rewrote the marker to
  753.   accommodate them with more reasonable efficiency.  This
  754.   change should also speed up marking for GC_malloc allocated
  755.   objects a little.  See gc_typed.h for new primitives.
  756. - Improved debugging facilities slightly.  Allocation time
  757.   stack traces are now kept by default on SPARC/SUNOS4.
  758.   (Thanks to Scott Schwartz.)
  759. - Added better support for small heap applications.
  760. - Significantly extended cord package.  Fixed a bug in the
  761.   implementation of lazily read files.  Printf and friends now
  762.   have cord variants.  Cord traversals are a bit faster.
  763. - Made ALL_INTERIOR_POINTERS recognition the default.
  764. - Fixed de so that it can run in constant space, independent
  765.   of file size.  Added simple string searching to cords and de.
  766. - Added the Hull-Ellis C++ interface.
  767. - Added dynamic library support for OSF/1.
  768.   (Thanks to Al Dosser and Tim Bingham at DEC.)
  769. - Changed argument to GC_expand_hp to be expressed
  770.   in units of bytes instead of heap blocks.  (Necessary
  771.   since the heap block size now varies depending on
  772.   configuration.  The old version was never very clean.)
  773. - Added GC_get_heap_size().  The previous "equivalent"
  774.   was broken.
  775. - Restructured the Makefile a bit.  
  776.  
  777. Since version 4.0:
  778. - Changed finalization implementation to guarantee that
  779.   finalization procedures are called outside of the allocation
  780.   lock, making direct use of the interface a little less dangerous.
  781.   MAY BREAK EXISTING CLIENTS that assume finalizers
  782.   are protected by a lock.  Since there seem to be few multithreaded
  783.   clients that use finalization, this is hopefully not much of
  784.   a problem.
  785. - Fixed a gross bug in CORD_prev.
  786. - Fixed a bug in blacklst.c that could result in unbounded
  787.   heap growth during startup on machines that do not clear
  788.   memory obtained from the OS (e.g. win32S).
  789. - Ported de editor to win32/win32S.  (This is now the only
  790.   version with a mouse-sensitive UI.)
  791. - Added GC_malloc_ignore_off_page to allocate large arrays
  792.   in the presence of ALL_INTERIOR_POINTERS.
  793. - Changed GC_call_with_alloc_lock to not disable signals in
  794.   the single-threaded case.
  795. - Reduced retry count in GC_collect_or_expand for garbage
  796.   collecting when out of memory.
  797. - Made uncollectable allocations bypass black-listing, as they
  798.   should.
  799. - Fixed a bug in typed_test in test.c that could cause (legitimate)
  800.   GC crashes.
  801. - Fixed some potential synchronization problems in finalize.c
  802. - Fixed a real locking problem in typd_mlc.c.
  803. - Worked around an AIX 3.2 compiler feature that results in
  804.   out of bounds memory references.
  805. - Partially worked around an IRIX5.2 beta problem (which may
  806.   or may not persist to the final release).
  807. - Fixed a bug in the heap integrity checking code that could
  808.   result in explicitly deallocated objects being identified as
  809.   smashed.  Fixed a bug in the dbg_mlc stack saving code
  810.   that caused old argument pointers to be considered live.
  811. - Fixed a bug in CORD_ncmp (and hence CORD_str).
  812. - Repaired the OS2 port, which had suffered from bit rot
  813.   in 4.0.  Worked around what appears to be CSet/2 V1.0
  814.   optimizer bug.
  815. - Fixed a Makefile bug for target "c++".
  816.